package com.ruoyi.common.enums;

import java.util.ArrayList;
import java.util.List;

public enum  TxnType {
    WITHDRAW_CNN(1, "提现", AmountType.CNN_WITHDRAW, TxnTypeGroup.WITHDRAW),
    WITHDRAW_CNN_BACK(2, "提现失败", AmountType.CNN_WITHDRAW, TxnTypeGroup.WITHDRAW),
    WITHDRAW_VC(3, "提币", AmountType.VC, TxnTypeGroup.WITHDRAW),
    WITHDRAW_VC_BACK(4, "提币失败", AmountType.VC, TxnTypeGroup.WITHDRAW),
    RECHARGE_CNN(5, "充值CNN", AmountType.CNN, TxnTypeGroup.RECHARGE),
    BUY_PRODUCT(6, "购买理财", AmountType.CNN, TxnTypeGroup.TRADE),
    BUY_VC_CNN(7, "购买VC", AmountType.CNN, TxnTypeGroup.TRADE),
    BUY_VC(8, "购买VC", AmountType.VC, TxnTypeGroup.TRADE),
    WITHDRAW_VC_WITHDRAW(9, "提币", AmountType.VC_WITHDRAW, TxnTypeGroup.WITHDRAW),
    WITHDRAW_VC_WITHDRAW_BACK(10, "提币失败", AmountType.VC_WITHDRAW, TxnTypeGroup.WITHDRAW),
    RELEASE_VC(11, "释放VC", AmountType.VC, TxnTypeGroup.TRADE),
    RELEASE_VC_WITHDRAW(12, "释放VC", AmountType.VC_WITHDRAW, TxnTypeGroup.TRADE),
    DIRECT_REWARD(13, "直推奖励", AmountType.CNN, TxnTypeGroup.TRADE),
    TEAM_REWARD(14, "团队奖励", AmountType.CNN, TxnTypeGroup.TRADE),
    TRANSFER(15, "划转", null, TxnTypeGroup.TRADE),
    TRADE(16, "交易", null, TxnTypeGroup.TRADE),
    TRADE_COMMISSION(17, "交易手续费", null, TxnTypeGroup.TRADE),
    TRADE_BACK(18, "交易余额返还", null, TxnTypeGroup.TRADE),
    VC_FUND_DAILY_PROFIT(19, "VC基金资产日收益", null, null),
    WITHDRAW_VC_CONSUME(20, "提币", AmountType.VC_CONSUME, TxnTypeGroup.WITHDRAW),
    CONSUME_VC(21, "消费", AmountType.VC, TxnTypeGroup.TRADE),
    CONSUME_VC_WITHDRAW(22, "消费", AmountType.VC_WITHDRAW, TxnTypeGroup.TRADE),
    CONSUME_VC_CONSUME(22, "消费", AmountType.VC_CONSUME, TxnTypeGroup.TRADE),
    ;

    /**
     * 流水类型编码
     */
    private int code;
    /**
     * 流水类型名称
     */
    private String name;
    /**
     * 金额类型
     */
    private AmountType amountType;

    /**
     * 流水分组
     */
    private TxnTypeGroup txnTypeGroup;
    TxnType(int code, String name, AmountType amountType, TxnTypeGroup txnTypeGroup) {
        this.code = code;
        this.name = name;
        this.amountType = amountType;
        this.txnTypeGroup = txnTypeGroup;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public AmountType getAmountType() {
        return amountType;
    }

    public void setAmountType(AmountType amountType) {
        this.amountType = amountType;
    }

    public TxnTypeGroup getTxnTypeGroup() {
        return txnTypeGroup;
    }

    public void setTxnTypeGroup(TxnTypeGroup txnTypeGroup) {
        this.txnTypeGroup = txnTypeGroup;
    }

    public static List<Integer> getCodeListByGroup(TxnTypeGroup txnTypeGroup) {
        List<Integer> codeList = new ArrayList<>();
        for(TxnType type : TxnType.values()) {
            if(txnTypeGroup == TxnTypeGroup.ALL || type.getTxnTypeGroup() == txnTypeGroup) {
                codeList.add(type.getCode());
            }
        }
        return codeList;
    }

    public static TxnType getByCode(int code) {
        TxnType[] array = TxnType.values();
        TxnType temp = null;
        for (int i = 0; i < array.length; i++) {
            temp = array[i];
            if (code == temp.getCode()) {
                return temp;
            }
        }
        return null;
    }
}
